<?php
namespace Api\Controller;
use Think\Controller;

class HotelController extends BaseController {

   private $m = NULL;
   private $md = NULL;
   private $navName = '订单管理';


   public function _initialize(){
   		parent::_initialize();
		$this->m = M('shop');
		$this->md = M('shop_detail');
		
		
   }
    	 	
	/**   聚餐美食-猜你喜欢  liuq
	*
	*/	
  
   public  function slist(){
  
       //$cid = I('cid');//  用户标识  member id
     $data = $this->m->where('(shop_level_two = 5  OR  shop_level_two = 29)  AND buss_status = 2')->order('id desc')->select();      
  
       foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
              
                 }
                 

    returnApiData2('0','成功',$data, $data2,$data3);exit;	     
       
   }
   
   
  public  function  five_order(){  //  5  29
               $order_type  =  I('order_type'); //排序条件  1智能排序   2 离我最近   3 最新发布   4 价格最高  
               $data = $this->m->where('(shop_level_two = 5  OR  shop_level_two = 29)  AND buss_status = 2')->select();
              
     if( $order_type == 1){
         foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                 
                   foreach($data as $v){  
                      $flag[] = $v['add_time'];  
                   }  
                   array_multisort($flag, SORT_ASC, $data); 
                   
               }
               
               
               
    if( $order_type == 3){
                    
         foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                 
                   foreach($data as $v){  
                      $flag[] = $v['add_time'];  
                   }  
                   array_multisort($flag, SORT_DESC, $data); 
                
                }
              
                
                
     if($order_type == 4){
        foreach( $data as $key => $item){
           $data[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('per_consumption');
              $data[$key]['start_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('start_time'); 
                $data[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('stop_time'); 
                   $data[$key]['address'] = M('shop_detail')->where('s_id="'.$item['id'].'"')->getField('address'); //http://localhost:81/jdrapia/Uploads/1.jpg
                     $data[$key]['shop_heapic'] = $this->md->where("s_id=".$item['id'])->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
                }
                  foreach($data as $v){  
                         $flag[] = $v['per_consumption'];  
                   }  
                  array_multisort($flag, SORT_DESC, $data); 
        }
        
       // dump($data);exit;
       returnApiData2('0','成功',$data, $data2,$data3);exit;	
               
               
   }
   
           public  function  shop_detail(){
                   $mid = I('mid');
                   $shop_id = $this->m->where('mid="'.$mid.'"')->getField('id');
                   $dataInfo = $this->md->where('s_id="'.$shop_id.'"')->find();
                   
                   $data['shop_toppics']  =  $dataInfo['shop_toppics']?__VUPLOAD__.'shop_toppics/'.$dataInfo['shop_toppics']:"";
                   $data['shop_heapic']  =  $dataInfo['shop_heapic']?__VUPLOAD__.'shop_heapic/'.$dataInfo['shop_heapic']:"";
                   $data['shop_name'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_name');
                   $data['shop_intro'] = M('shop')->where('mid="'.$mid.'"')->getField('shop_intro');    
                   $data['address'] = M('shop_detail')->where('s_id="'.$shop_id.'"')->getField('address'); 
                   $data['shop_intropics'] = $dataInfo['shop_intropics'];  
                   $data['per_consumption'] = $dataInfo['per_consumption'];   
                   $data['telephone'] = M('shop_detail')->where('s_id="'.$shop_id.'"')->getField('telephone');  
                  // $data['class_name'] = M('shop_product_class')->where('id="'.$dataInfo['shop_level_three'].'"')->getField('class_name');
                       
                   $attitude = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('attitude_star'); 
                   $speed = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('speed_star'); 
                   $taste = M('shop_evaluate')->where('mid="'.$mid.'"')->sum('taste_star'); 
                   $evaluate_times = M('shop_evaluate')->where('mid="'.$mid.'"')->count();
                   $comment_star = round(( $attitude  + $speed + $taste )/( $evaluate_times*3 ));  
                   $data['comment_star_num'] = $comment_star;
                    
                   if(  $comment_star == 1 ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."1star.png";
                   }elseif(   $comment_star == 2  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."2star.png";
                   }elseif(   $comment_star == 3  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."3star.png";
                   }elseif(   $comment_star == 4  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."4star.png";
                   }elseif(   $comment_star == 5  ){
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."5star.png";
                   }else{
                      $data['comment_star_value'] = __VUPLOAD__.'evaluate/'."6star.png";
                   }
                   
                  
                   returnApiData2('0','成功',$data, $data2,$data3);exit;	
           }
           
           
    public function   price_order(){
        
         $from_money = I('from_money');
         $to_money = I('to_money');
//         $from_money = 18;
//         $to_money = 65;
         if($from_money){
		$where['per_consumption']= array('EGT',$from_money);
	 }
	if($to_money){
		$where['per_consumption']= array('ELT',$to_money);
         }		
		
       if($from_money && $to_money){
	        $where['per_consumption']=array(array('EGT',$from_money),array('ELT',$to_money),'and');
        }	
        
     // $this->m->where('(shop_level_two = 8  OR  shop_level_two = 32)  AND buss_status = 2')->select();
        $data = $this->md->where($where)->order('id desc')->select();
        
        
         foreach ($data as $key => $value) {
           
            $shop_level_two = M('shop')->where("id=".$value['s_id'])->getField('shop_level_two');
            $shop=M('shop')->where("id=".$value['s_id'])->find();
             
            if( $shop_level_two== 5 || $shop_level_two == 29){
                  $string.=$shop['id'].'|';
           
              }
            
         }
         
          $array=explode("|", $string);
          array_pop($array);
          foreach ($array as $key => $value) {
           $data4[$key]['shop_name'] = M('shop')->where('id="'.$value.'"')->getField('shop_name');
              $data4[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('per_consumption');
                $data4[$key]['start_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('start_time'); 
                    $data4[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('stop_time'); 
                      $data4[$key]['address'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('address'); 
                         $data4[$key]['shop_heapic'] = $this->md->where('s_id="'.$value.'"')->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
  
           }
           // dump($data4);exit;
            returnApiData2('0','成功',$data4, $data2,$data3);exit;
        
      }
      
     public  function choice(){
         
       
         $room_type = I('room_type'); //1床房   2单人床 3 双人床  4其他
       
         if(!empty($room_type)){
             $where['room_type'] = $room_type;
         }
        
         
         $data = $this->md->where($where)->order('id desc')->select();
         
 
      foreach ($data as $key => $value) {
           
            $shop_level_two = M('shop')->where("id=".$value['s_id'])->getField('shop_level_two');
            $shop=M('shop')->where("id=".$value['s_id'])->find();
             
            if( $shop_level_two== 5 || $shop_level_two == 29){
                  $string.=$shop['id'].'|';
           
              }
            
         }
         
          $array=explode("|", $string);
          array_pop($array);
          foreach ($array as $key => $value) {
           $data4[$key]['shop_name'] = M('shop')->where('id="'.$value.'"')->getField('shop_name');
              $data4[$key]['per_consumption'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('per_consumption');
                $data4[$key]['start_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('start_time'); 
                    $data4[$key]['stop_time'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('stop_time'); 
                      $data4[$key]['address'] = M('shop_detail')->where('s_id="'.$value.'"')->getField('address'); 
                         $data4[$key]['shop_heapic'] = $this->md->where('s_id="'.$value.'"')->getField('shop_heapic')?__VUPLOAD__.'shop_heapic/'.$this->md->where("s_id=".$item['id'])->getField('shop_heapic'):""; //店铺头像
  
           }
           
            returnApiData2('0','成功',$data4, $data2,$data3);exit;
   }
             
    
   
      
     

}